from framework.event import Event
from framework.eventsource import EventSource
from framework.scrapeutils import *

def get_events():
    return TheBongoClub().get_events()

class TheBongoClub(EventSource):

    def get_events(self):
        url = 'http://www.thebongoclub.co.uk/webpages/programme.php'
        resp = http_get(url)
        tree = build_tree(resp)
        eventnodes = tree.xpath('.//td[h2[@class="event-title"]]')
        return map(_extract_event, eventnodes)

def _extract_event(eventnode):
    heading = eventnode.xpath('h2')[0].text_content()
    title, date = heading.rsplit(' - ', 1)
    return Event(
        title=title,
        start_datetime=date
    )
